/**
 * Project Reactor
 */


#ifndef _TCPCONNECTION_H
#define _TCPCONNECTION_H
#include "InetAddress.h"
#include "Socket.h"
#include "SocketIO.h"
#include <string>
#include <functional>
#include <memory>
using std::shared_ptr;
using std::function;
using std::string;


class TcpConnection;
using TcpConnectionPtr = shared_ptr<TcpConnection>;
using Callback = function<void(TcpConnectionPtr)>;
class TcpConnection 
:public std::enable_shared_from_this<TcpConnection>{
public: 
    
TcpConnection(int fd);
    
string recv();
    
/**
 * @param msg
 */
void send(const string msg);
bool isClosed();
string toString();

void setAllCallbacks(Callback &Close, Callback &Msg, Callback &On);
void handleConnectionCallback();
void handleMessageCallback();
void handleCloseCallback();
private: 
    Socket _sock;
    SocketIO _socketIO;
    InetAddress _localAddr;
    InetAddress _peerAddr;

    Callback _onConnection;
    Callback _onClose;
    Callback _onMessage;
    
InetAddress getLocalAddr();
    
InetAddress getPeerAddr();
};

#endif //_TCPCONNECTION_H
